package com.shenzhenai.jetpackcomposelayouts

import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.absolutePadding
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.LocalContentColor
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocal
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp

/**
 * @author huangzehui
 * @date 28/7/2025 下午10:08 周一
 * @description
 */

@Composable
fun PhotographerCard(modifier: Modifier = Modifier) {
    Row(
        // modifier 外部传递进来的时候已经有个topPadding，这个会让内容再状态栏下面，还有 padding 是会叠加的
        // 调用多次 padding 值，那么 padding 就会一直叠加
        modifier = modifier
            // 设置圆角
            .clip(RoundedCornerShape(4.dp))
            // 设置背景颜色
            .background(color = MaterialTheme.colorScheme.surface)
            // 设置点击事件，这个必须放在padding之前，这样点击，padding部分也会有水波纹，否则点击只有内容部分有水波纹，padding部分没有
            .clickable(onClick = {})
            // 设置内边距，会叠加，多调几次，padding会更大
            .padding(all = 16.dp)
    ) {
        Surface(
            modifier = Modifier
                // 设置大小
                .size(50.dp),
            // 设置原形
            shape = CircleShape,
            // 设置颜色
            color = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.2f),
        ) {
            Image(
                painter = painterResource(id = R.drawable.profile_picture),
                contentDescription = null,
            )
        }

        Column(
            modifier = Modifier
                // 设置左边内边距
                .padding(start = 8.dp)
                // 设置子视图垂直居中
                .align(Alignment.CenterVertically)
        ) {
            Text(
                text = "Alfred Sisley",
                // 设置字体权重
                fontWeight = FontWeight.Bold,
            )

            /**
             * 使用 CompositionLocalProvider 进行隐式传参
             *
             * LocalContentAlpha 在 m2 和 m3 的区别
             * https://developer.android.com/develop/ui/compose/designsystems/material2-material3?hl=zh-cn#m2_16
             *
             *
             * m2
             * import androidx.compose.material.ContentAlpha
             * import androidx.compose.material.LocalContentAlpha
             *
             * // High emphasis
             * CompositionLocalProvider(LocalContentAlpha provides ContentAlpha.high) {
             *     Icon(…)
             * }
             * // Medium emphasis
             * CompositionLocalProvider(LocalContentAlpha provides ContentAlpha.medium) {
             *     Icon(…)
             * }
             * // Disabled emphasis
             * CompositionLocalProvider(LocalContentAlpha provides ContentAlpha.disabled) {
             *     Icon(…)
             * }
             *
             * m3
             *
             * import androidx.compose.material3.LocalContentColor
             *
             * // High emphasis
             * CompositionLocalProvider(LocalContentColor provides MaterialTheme.colorScheme.onSurface) {
             *     Icon(…)
             * }
             * // Medium emphasis
             * CompositionLocalProvider(LocalContentColor provides MaterialTheme.colorScheme.onSurfaceVariant) {
             *     Icon(…)
             * }
             * // Disabled emphasis
             * CompositionLocalProvider(LocalContentColor provides MaterialTheme.colorScheme.onSurface.copy(alpha = 0.38f)) {
             *     Icon(…)
             * }
             *
             */
            CompositionLocalProvider(
                /**
                 * 这里使用 infix 进行方法的写法
                 *
                 * 正常方法调用
                 * LocalContentColor.provides(MaterialTheme.colorScheme.onSurfaceVariant)
                 *
                 * infix 修饰后可以的调用
                 * LocalContentColor provides MaterialTheme.colorScheme.onSurfaceVariant
                 *
                 *
                 * 在 CompositionLocalProvider 包裹下的子组件，都会使用这个颜色值
                 */
                LocalContentColor provides MaterialTheme.colorScheme.onSurfaceVariant
            ) {
                Text(
                    text = "3 minute ago",
                    style = MaterialTheme.typography.bodyMedium,
                )
            }

        }
    }
}